/**
 * Created by zhongb on 2017/4/11.
 */
var status = {"new":'新建',
    "sent":'已发货',
    "received":'已收货'};
require('layout/util');
require('jquery');
require('easyui');

//获取url参数
var asnCode = $.getUrlParam("noteCode");
var asnId = $.getUrlParam("asnId");
//页面数据初始化
dataInit(asnCode,asnId,status);

function dataInit(value,asnId) {
    $.ajax({
        url:'api/v1/p/mms/shipping/note/query',
        type:'get',
        data:{
            noteCode:value
        },
        dataType:'json'
    })
        .done(function (result) {
            if(result.code == '200'){
                var data = result.data;
                var $firstTarget = $("#asn_info").find("span");
                var $secondTarget = $("#logistics_info").find("span");
                //元素赋值
                $firstTarget.eq(0).text(data.code);
                $firstTarget.eq(2).text(data.startWarehouse);
                $firstTarget.eq(3).text(data.totalNum);
                $firstTarget.eq(4).text(data.totalVolumn);
                $firstTarget.eq(5).text(data.totalWeight);
                $firstTarget.eq(6).text(status[data.shippingStatus]);
                $firstTarget.eq(7).text(data.receiveDt);
                $secondTarget.eq(0).text(data.destWarehouse);
                $secondTarget.eq(1).text(data.logisticsName);
                $secondTarget.eq(2).text(data.startPort);
                $secondTarget.eq(3).text(data.transferPort);
                $secondTarget.eq(4).text(data.destferPort);
                $secondTarget.eq(5).text(data.estimateLeaveDt);
                $secondTarget.eq(6).text(data.estimateArriveDt);
                $secondTarget.eq(7).text();
                $secondTarget.eq(8).text();
                $secondTarget.eq(9).text(data.voyageNo);
                $secondTarget.eq(10).text(data.providerName);
                $secondTarget.eq(11).text(data.memo);
                tableInit(asnId);
                /*var boxList = data.boxList;
                var tableData = {};
                var total = boxList.length;
                var rows = [];
                $.each(boxList,function (i,o) {
                    var row = {};
                    row.code = o.code;
                    row.entName = o.entName;
                    row.boxCode = o.boxCode;
                    row.skuNum = o.skuNum;
                    row.goodsNum = o.goodsNum;
                    rows.push(row);
                });
                tableData.total = total;
                tableData.rows = rows;
                $("#main_table").datagrid('loadData',tableData);*/
            }else{
                alert(result.message);
            }
        });
}
function tableInit(asnId) {
    $("#main_table").datagrid({
        url:'api/v1/p/mms/shipping/note/boxList',
        border : false,
        pagination : true,
        pageSize : 10,
        pageList : [ 10, 20, 50, 100 ],
        rownumbers:true,
        emptyMsg : "暂无数据",
        queryParams: {
            noteId: asnId
        },
        columns:[[
            {
                field : 'code',
                title : '包裹码',
                width : '27%'
            },{
                field : 'boxCode',
                title : '箱号',
                width : '27%'
            },{
                field : 'skuNum',
                title :'SKU数量',
                width : '10%'
            },{
                field : 'goodsNum',
                title : '商品件数',
                width : '10%'
            },{
                field : 'entName',
                title : '客户名称',
                width : '27%'
            }]],
        onClickRow: function (rowIndex, rowData) {
            $(this).datagrid('unselectRow', rowIndex);
        },
        loadFilter:function(data){
            if(data.code=='200'){
                return data.data;
            }else{
                alert(data.message);
            }
        }
    });
}